package com.globalresources.ui.struts.action.relation;

import java.util.List;

import com.globalresources.business.inface.IRelationService;
import com.globalresources.business.inface.IUserService;
import com.globalresources.commons.AbstractAction;
import com.globalresources.commons.Pager;
import com.globalresources.commons.PagerService;
import com.globalresources.commons.StringHelper;
import com.globalresources.po.Relation;
import com.globalresources.po.User;

/**
 * @author aaron.lu(luzhiyuan) E-mail:atyuan.lu@gmail.com
 * @since 创建时间：Jul 14, 2009 4:48:11 PM
 */
public class RelationAction extends AbstractAction {

	private static final long serialVersionUID = 1L;
	
	private String pusername;
	private String pauthority;
	private Pager pager;	
	private PagerService pagerService;
	private IRelationService relationService;
	private String currentPage;
	private String pagerMethod;
	private String totalRow;
	private List<Relation> relations;
	private String relationid;
	private Relation relation;
	private String userid;
	
	
	public String load()throws Exception{
		if (StringHelper.isNotEmpty(relationid)) {
			setRelation(relationService.getRelation(new Integer(relationid)));
		}else{
			setRelation(null);
		}
		return SUCCESS;
	}
	
	public String list()throws Exception{	
		int _totalRow = relationService.countRelations(pusername, pauthority);
		pager = pagerService.getPager(currentPage, pagerMethod, _totalRow);
		setCurrentPage(String.valueOf(pager.getCurrentPage()));
		setTotalRow(String.valueOf(_totalRow));
		relations = relationService.getRelations(pusername, pauthority);
		return SUCCESS;
	}
	
	public String delete()throws Exception{
		if (StringHelper.isNotEmpty(relationid)) {
			Relation _relation = relationService.getRelation(new Integer(relationid));
			if (null != _relation) {
				relationService.deleteRelation(_relation);
			}
		}
		return SUCCESS;
	}
	
	public String save(){
		if (null != relation) {
			relationService.saveRelation(relation);
		}
		return SUCCESS;
	}
	
	public String insert(){
		
		
		return SUCCESS;
	}



	public String getPusername() {
		return pusername;
	}



	public void setPusername(String pusername) {
		this.pusername = pusername;
	}



	public String getPauthority() {
		return pauthority;
	}



	public void setPauthority(String pauthority) {
		this.pauthority = pauthority;
	}



	public Pager getPager() {
		return pager;
	}



	public void setPager(Pager pager) {
		this.pager = pager;
	}



	public PagerService getPagerService() {
		return pagerService;
	}



	public void setPagerService(PagerService pagerService) {
		this.pagerService = pagerService;
	}



	public IRelationService getRelationService() {
		return relationService;
	}



	public void setRelationService(IRelationService relationService) {
		this.relationService = relationService;
	}



	public String getCurrentPage() {
		return currentPage;
	}



	public void setCurrentPage(String currentPage) {
		this.currentPage = currentPage;
	}



	public String getPagerMethod() {
		return pagerMethod;
	}



	public void setPagerMethod(String pagerMethod) {
		this.pagerMethod = pagerMethod;
	}



	public String getTotalRow() {
		return totalRow;
	}



	public void setTotalRow(String totalRow) {
		this.totalRow = totalRow;
	}



	public static long getSerialVersionUID() {
		return serialVersionUID;
	}



	public List<Relation> getRelations() {
		return relations;
	}



	public void setRelations(List<Relation> relations) {
		this.relations = relations;
	}


	public Relation getRelation() {
		return relation;
	}

	public void setRelation(Relation relation) {
		this.relation = relation;
	}

	public String getRelationid() {
		return relationid;
	}

	public void setRelationid(String relationid) {
		this.relationid = relationid;
	}

	public String getUserid() {
		return userid;
	}

	public void setUserid(String userid) {
		this.userid = userid;
	}
	
	
	
	

}
